public class search {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9,};
        System.out.println(search1(arr,3));
    }
    public static int search1(int[] arr,int num){
        int left = 0;
        int right = arr.length-1;
        while (left <= right){
            int mid = (arr[left]+arr[right])/2;
            if(num<arr[mid]){
                right = mid-1;
            }else if(num>arr[mid]){
                right = mid+1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}

